unit OrderSearchForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, SpecialInfoHandle, EmployeeSelForm;

type
  TfrmOrderSearch = class(TForm)
    Label1: TLabel;
    edtBillNo: TEdit;
    Label4: TLabel;
    edtEmployee: TEdit;
    btnEmployee: TButton;
    lblCustomer: TLabel;
    edtSupplier: TEdit;
    btnSupplier: TButton;
    Label2: TLabel;
    dtpBillBegin: TDateTimePicker;
    btnOk: TButton;
    btnCancel: TButton;
    dtpBillEnd: TDateTimePicker;
    Label3: TLabel;
    btnDelCustomer: TButton;
    btnDelEmployee: TButton;
    lbl1: TLabel;
    procedure btnDelCustomerClick(Sender: TObject);
    procedure btnDelEmployeeClick(Sender: TObject);
    procedure btnSupplierClick(Sender: TObject);
    procedure btnEmployeeClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    FEmployeeID: Integer;
    FCustomerID: Integer;
    FSpecialInfoHandle: TSpecialInfoHandle;
    procedure SetCustomerID(const Value: Integer);
    procedure SetEmployeeID(const Value: Integer);
    procedure SetSpecialInfoHandle(const Value: TSpecialInfoHandle);
    { Private declarations }
  public
    { Public declarations }

    property EmployeeID: Integer read FEmployeeID write SetEmployeeID;
    property CustomerID: Integer read FCustomerID write SetCustomerID;

    property SpecialInfoHandle: TSpecialInfoHandle read FSpecialInfoHandle write SetSpecialInfoHandle;
  end;

var
  frmOrderSearch: TfrmOrderSearch;

implementation

uses DataType, BaseADOHandle;

{$R *.dfm}

{ TfrmOrderSearch }

procedure TfrmOrderSearch.btnDelCustomerClick(Sender: TObject);
begin
  FCustomerID := C_NoValidKeyID;
  edtSupplier.Text := '';
end;

procedure TfrmOrderSearch.btnDelEmployeeClick(Sender: TObject);
begin
  FEmployeeID := C_NoValidKeyID;
  edtEmployee.Text := '';
end;

procedure TfrmOrderSearch.btnEmployeeClick(Sender: TObject);
begin
  if not Assigned(frmEmployeeSel) then
  begin
    frmEmployeeSel:= TfrmEmployeeSel.Create(nil);
  end;

  if frmEmployeeSel.ShowModal = mrOk then
  begin
    FEmployeeID := frmEmployeeSel.SelectedEmployee.EmployeeID;
    edtEmployee.Text := frmEmployeeSel.SelectedEmployee.Employee;
  end;
end;

procedure TfrmOrderSearch.btnSupplierClick(Sender: TObject);
var
  aSelCustomer: TBaseADOData;
begin
  inherited;

  aSelCustomer := TBaseADOData.Create;
  try
    if FSpecialInfoHandle.SelectData(Special_Customer, aSelCustomer) then
    begin
      edtSupplier.Text := aSelCustomer.Number;//aSelCustomer.Name;
      FCustomerID := aSelCustomer.ID;
    end;
  finally
    aSelCustomer.Free;
  end;
end;

procedure TfrmOrderSearch.FormCreate(Sender: TObject);
begin
  dtpBillBegin.DateTime := Now;
  dtpBillEnd.DateTime := Now;
end;

procedure TfrmOrderSearch.SetCustomerID(const Value: Integer);
begin
  FCustomerID := Value;
end;

procedure TfrmOrderSearch.SetEmployeeID(const Value: Integer);
begin
  FEmployeeID := Value;
end;


procedure TfrmOrderSearch.SetSpecialInfoHandle(const Value: TSpecialInfoHandle);
begin
  FSpecialInfoHandle := Value;
end;

end.
